import request from '@/config/axios'
import {ServicePrefixEnum} from "@/enums/commonEnum";
import {RequestEnum} from "@/enums/httpEnum";
import type {AxiosRequestConfig} from "axios";
import {defHttp} from "@/utils/http/axios";

export interface PostVO {
  id?: number
  name: string
  code: string
  sort: number
  status: number
  remark: string
  createTime?: Date
}

const MODULAR = '/system/post';

export const Api ={
  GetPostPage:{
    url: `${ServicePrefixEnum.BASE}/${MODULAR}/page`,
    method: RequestEnum.GET,
  } as AxiosRequestConfig,
  GetSimplePostList:{
    url: `${ServicePrefixEnum.BASE}/${MODULAR}/simple-list`,
    method: RequestEnum.GET,
  } as AxiosRequestConfig,
  GetPost:{
    url: `${ServicePrefixEnum.BASE}/${MODULAR}/get`,
    method: RequestEnum.GET,
  } as AxiosRequestConfig,
  CreatePost:{
    url: `${ServicePrefixEnum.BASE}/${MODULAR}/create`,
    method: RequestEnum.POST,
  } as AxiosRequestConfig,
  UpdatePost:{
    url: `${ServicePrefixEnum.BASE}/${MODULAR}/update`,
    method: RequestEnum.PUT,
  } as AxiosRequestConfig,
  DeletePost:{
    url: `${ServicePrefixEnum.BASE}/${MODULAR}/delete`,
    method: RequestEnum.DELETE,
  } as AxiosRequestConfig,
}

// 查询岗位列表
export const getPostPage = (params) => {
  return defHttp.request({ ...Api.GetPostPage,params})
}

// 获取岗位精简信息列表
export const getSimplePostList = async (): Promise<PostVO[]> => {
  return await defHttp.request({ ...Api.GetSimplePostList})
}

// // 获取岗位精简信息列表
// export const getSimplePostList = async (): Promise<PostVO[]> => {
//   return await request.get({ url: '/system/post/simple-list' })
// }

// 查询岗位详情
export const getPost = (id) => {
  let params = {id:id}
  return defHttp.request({ ...Api.GetPost,params})
}

// 新增岗位
export const createPost = (data) => {
  return defHttp.request({ ...Api.CreatePost,params:data})
}

// 修改岗位
export const updatePost = (data) => {
  return defHttp.request({ ...Api.UpdatePost,params:data})
}

// 删除岗位
export const deletePost = (id) => {
  let params = {id:id}
  return defHttp.request({ ...Api.DeletePost,params})
}

// 导出岗位 todo
export const exportPost = async (params) => {
  return await request.download({ url: '/system/post/export', params })
}
